﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class MsgItem : MonoBehaviour
{

	public Text msgContentText;
	public Text msgTimeText;
	public Image leftAvatarImg;
	public Image rightAvatarImg;

	private MsgDO _msgDo;

	public MsgDO MsgDo
	{
		get { return _msgDo; }
		set { _msgDo = value; }
	}

	/// <summary>
	/// 更新显示-外部调用
	/// </summary>
	public void SyncShow()
	{
		if (_msgDo.ActiveAvatar.Equals("left"))
		{
			leftAvatarImg.gameObject.SetActive(true);
			rightAvatarImg.gameObject.SetActive(false);
			msgContentText.alignment = TextAnchor.MiddleLeft;
		}else if (_msgDo.ActiveAvatar.Equals("right"))
		{
			leftAvatarImg.gameObject.SetActive(false);
			rightAvatarImg.gameObject.SetActive(true);
			msgContentText.alignment = TextAnchor.MiddleRight;
		}
		else
		{
			//未处理情况，都禁用
			leftAvatarImg.gameObject.SetActive(false);
			rightAvatarImg.gameObject.SetActive(false);
		}
		msgContentText.text = _msgDo.Content;
		msgTimeText.text = _msgDo.ReceiveTime;
		//头像拉取(不用重复获取-在打开ChatPanel的时候就已经)
		leftAvatarImg.sprite = HttpTool.Instance.OpponentSprite;
		rightAvatarImg.sprite = HttpTool.Instance.LocalSprite;


	}
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}
}
